package com.ssy.lingxi.product.entity.commodity.member;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.product.entity.commodity.Commodity;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 商品价格策略实体
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/1/11
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "product_commodity_unitPrice_strategy")
public class CommodityUnitPriceStrategy implements Serializable {
    private static final long serialVersionUID = -8662223491724316477L;
    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="commodity_unitPrice_strategy_seq")
    @SequenceGenerator(sequenceName="product_commodity_unitPrice_strategy_seq", name="commodity_unitPrice_strategy_seq",allocationSize = 1)
    private Long id;

    /**
     * 商品价格策略名称
     */
    @Column(columnDefinition = "varchar(90)", nullable = false)
    private String name;

    /**
     * 商城id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long shopId;

    /**
     * 商城类型：1.企业商城 2.积分商城 3.渠道商城 4.渠道自有商城 5.渠道积分商城
     */
    @Column(columnDefinition = "int")
    private Integer type;

    /**
     * 商城环境:1.web 2.H5 3.小程序 4.IOS 5.安卓
     */
    @Column(columnDefinition = "int")
    private Integer environment;

    /**
     * 商品id
     */
    @JsonIgnore
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name="commodityId",referencedColumnName = "id")
    private Commodity commodity;

    /**
     * 产品定价：1-现货价格, 2-价格需要询价, 3-积分兑换商品
     */
    @Column(columnDefinition = "int", nullable = false)
    private Integer priceType;

    /**
     * 最小(价格/积分)
     */
    @Column(columnDefinition = "decimal")
    private Double min;

    /**
     * 最大(价格/积分)
     */
    @Column(columnDefinition = "decimal")
    private Double max;

    /**
     * 商品价格
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "commodityUnitPriceStrategy", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    private List<CommodityMemberUnitPrice> memberUnitPriceList;

    /**
     * 是否会员级别(否：代表是商城级别)
     */
    @Column(columnDefinition = "boolean")
    private Boolean isMember;

    /**
     * 适用类型：1-会员; 2-会员等级;
     * UnitPriceStrategyApplyTypeEnum枚举
     */
    @Column(columnDefinition = "int")
    private Integer applyType = 1;

    /**
     * 适用会员
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "commodityUnitPriceStrategy", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    private List<CommodityMember> commodityMemberList;

    /**
     * 适用会员等级
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "commodityUnitPriceStrategy", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    private List<CommodityMemberLevel> commodityMemberLevelList;

    /**
     * 是否有效
     */
    @Column(columnDefinition = "boolean", nullable = false)
    private Boolean isEnable;

    /**
     * 会员id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long memberId;

    /**
     * 会员名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String memberName;

    /**
     * 会员角色id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long memberRoleId;

    /**
     * 会员角色名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String memberRoleName;

    /**
     * 用户id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long userId;

    /**
     * 用户名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String userName;

    /**
     * 创建时间
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long createTime = System.currentTimeMillis();
}
